"""
Case Type   : 系统内部使用工具
Case Name   : 主机执行gs_ctl query使用-D指定正确数据库实例目录是否成功
Create At   : 2021/01/21
Owner       : opentestcase015
Description :
    1.指定正确的数据库实例目录主机执行query
Expect      :
    1.指定正确的数据库实例目录主机执行query成功
History     :
"""

import unittest

from testcase.utils.Constant import Constant
from testcase.utils.Logger import Logger
from yat.test import Node
from yat.test import macro

LOG = Logger()


class SystemInternalTools(unittest.TestCase):
    def setUp(self):
        LOG.info('------------------this is setup------------------')
        LOG.info('---Opengauss_Function_Tools_gs_ctl_Case0088开始执行-----')
        self.constant = Constant()
        self.PrimaryNode = Node('PrimaryDbUser')

    def test_system_internal_tools(self):
        LOG.info('-----------------查询主机状态---------------------')
        status_cmd = f'''source {macro.DB_ENV_PATH};
            gs_ctl query -D {macro.DB_INSTANCE_PATH} ;
            '''
        LOG.info(status_cmd)
        status_msg = self.PrimaryNode.sh(status_cmd).result()
        LOG.info(status_msg)
        self.assertIn('Normal', status_msg)

    def tearDown(self):
        LOG.info('--------------this is tearDown--------------')
        # 无需清理环境
        LOG.info('----Opengauss_Function_Tools_gs_ctl_Case0088执行完成----')
